<!--计量单位选择框-->
<template>
  <div>
    <BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="800px"
      @ok="handleOk" destroyOnClose @visible-change="visibleChange">
      <BasicTable :columns="columns" v-bind="config" :useSearchForm="true" :formConfig="formConfig"
        :api="getPreMrpResultList" :searchInfo="searchInfo" :rowSelection="rowSelection"
        :indexColumnProps="indexColumnProps">
      </BasicTable>
    </BasicModal>
  </div>
</template>
<script lang="ts">
  import {
    defineComponent,
    ref,
    unref
  } from 'vue';
  import {
    BasicModal,
    useModalInner
  } from '/@/components/Modal';
  import {
    getPreMrpResultList
  } from './base.api';
  import {
    createAsyncComponent
  } from '/@/utils/factory/createAsyncComponent';
  import {
    useSelectBiz
  } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
  import {
    selectProps
  } from '/@/components/Form/src/jeecg/props/props';
  import {
    useAttrs
  } from '/@/hooks/core/useAttrs';
  export default defineComponent({
    name: 'planOrderListSelectModel',
    components: {
      BasicModal,
      BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
        loading: true,
      }),
    },
    props: {
      ...selectProps,
      modalTitle: {
        type: String,
        default: '选择前工序MRP运算结果',
      },
      multiple: {
        type: Boolean,
        default: true
      }
    },
    emits: ['register', 'getSelectResult'],
    setup(props, {
      emit
    }) {
      const [register, {
        closeModal
      }] = useModalInner(async (data) => {});
      const attrs = useAttrs();

      const config = {
        canResize: false,
        bordered: true,
        size: 'small',
        rowKey: unref(props).rowKey,
        labelKey: 'name',
        isRadioSelection: !(props.multiple == true) ?? true,
      };
      const getBindValue = Object.assign({}, unref(props), unref(attrs), config);
      const [{
        rowSelection,
        indexColumnProps,
        visibleChange,
        getSelectResult
      }] = useSelectBiz(getPreMrpResultList, getBindValue);

      rowSelection.columnWidth = 50;
      indexColumnProps.width = 50;
      const searchInfo = ref(props.params);
      //查询form
      const formConfig = {
        labelWidth: 100,
        baseColProps: {
          xs: 8,
          sm: 8,
        },
        schemas: [{
            label: '计划订单',
            field: 'planOrderCode',
            component: 'JInput',
            colProps: {
              span: 8
            },
          },
          {
            label: '产品',
            field: 'materialId',
            component: 'JInput',
            colProps: {
              span: 8
            },
          },
        ],
      };

      const columns = [
        // {
        //   title: '计划单号',
        //   dataIndex: 'billCode',
        //   width: 150
        // },
        // {
        //   title: '计划行号',
        //   dataIndex: 'rowNum',
        //   key: '',
        //   width: 100
        // },
        // {
        //   title: '生产组织',
        //   dataIndex: 'productOrganizationName',
        //   width: 120
        // },
        // {
        //   title: '版本号',
        //   dataIndex: 'resultVersion',
        //   width: 100
        // },
        {
          title: '销售订单号',
          dataIndex: 'orderBillCode',
          width: 150
        },
        {
          title: '销售行号',
          dataIndex: 'orderRowNumber',
          width: 120
        },
        {
          title: '料号',
          dataIndex: 'materialCode',
          width: 150
        }, {
          title: '品名',
          dataIndex: 'materialName',
          width: 150
        },
        // {
        //   title: '供应类型',
        //   dataIndex: 'supplyType',
        //   customRender: ({
        //     text
        //   }) => text == 0 ? '自制' : text == 1 ? '采购' : text == 2 ? '委外' : '',
        //   width: 120
        // }, {
        //   title: '工厂/供应商',
        //   dataIndex: 'supplierName',
        //   width: 120
        // }, {
        //   title: '订单数量',
        //   dataIndex: 'orderQuantity',
        //   width: 120
        // }, {
        //   title: 'MRP数量（毛需求）',
        //   dataIndex: 'mrpQuantity',
        //   width: 120
        // }, 
        {
          title: '调整后MRP数量（净需求）',
          dataIndex: 'adjustedMrpQuantity',
          width: 120
        },
        // {
        //   title: '释放量',
        //   dataIndex: 'releaseQuantity',
        //   width: 120
        // }, 
        {
          title: '需求日期',
          dataIndex: 'demandDate',
          width: 120
        },
        // {
        //   title: '开工日期',
        //   dataIndex: 'startDate',
        //   width: 120
        // }, 
        {
          title: '需求类型',
          dataIndex: 'demandType',
          customRender: ({
            text
          }) => text == 0 ? '独立' : text == 1 ? '相关' : '',
          width: 120
        },
        // {
        //   title: '释放状态',
        //   dataIndex: 'releaseStatus',
        //   customRender: ({
        //     text
        //   }) => text == 0 ? '未释放' : text == 1 ? '已释放' : '',
        //   width: 120
        // }, {
        //   title: '是否排产',
        //   dataIndex: 'productScheduleStatus',
        //   customRender: ({
        //     text
        //   }) => text == 0 ? '否' : text == 1 ? '是' : '',
        //   width: 120
        // }, 
        {
          title: '锁定状态',
          dataIndex: 'lockStatus',
          customRender: ({
            text
          }) => text == 0 ? '未锁定' : text == 1 ? '已锁定' : '',
          width: 120
        },
      ];

      function handleOk() {
        getSelectResult((options, values) => {
          //回传选项和已选择的值
          emit('getSelectResult', options, values);
          //关闭弹窗
          closeModal();
        });
      }

      return {
        config,
        handleOk,
        searchInfo,
        register,
        indexColumnProps,
        visibleChange,
        getPreMrpResultList,
        formConfig,
        getBindValue,
        columns,
        rowSelection,
      };
    },
  });

</script>
